﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using UserDefineForm.exception;
using UserDefineForm.formcomponent;
using UserDefineForm.control.propertymapping;

namespace UserDefineForm.control
{
    public class DesignableComboBox:DesignableControlBase
    {
        override public String Value
        {
            set
            {
                ComboBox comboBox = (ComboBox)this.control;
                comboBox.SelectedText = value;
            }

            get
            {
                ComboBox comboBox = (ComboBox)this.control;
                return comboBox.Text;
            }
        }

        public override List<string> ListValue
        {
            get
            {
                ComboBox comboBox = (ComboBox)this.control;
                List<string> list= new List<string>();
                foreach (object o in comboBox.Items)
                {
                    list.Add((string)o);
                }
                return list;
            }
            set
            {
                ComboBox comboBox = (ComboBox)this.control;
                comboBox.Items.Clear();
                foreach (string s in value)
                {
                    comboBox.Items.Add(s);
                }
            }
        }

        public DesignableComboBox(DesignPanel designPanel, PropertiesPanelv2 propPnl)
            : base(designPanel, propPnl)
        {
            this.control = new ComboBox();
            this.mainPnl.Controls.Add(this.control);
            this.mappingObject = new ComboBoxMappingObject();

            ((ComboBox)control).AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            ((ComboBox)control).DropDownStyle = ComboBoxStyle.DropDownList;
            control.Dock = DockStyle.Fill;
        }

        public override ControlType getType()
        {
            return ControlType.ComboBox;
        }
    }
}
